package com.smcdd.cdb.dbo.cdb_dbo.ui.activity;

import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;


import com.smcdd.cdb.dbo.cdb_dbo.R;
import com.smcdd.cdb.dbo.cdb_dbo.service.presenter.DateInfosPresenter;
import com.smcdd.cdb.dbo.cdb_dbo.service.view.IDateInfos;
import com.smcdd.cdb.dbo.cdb_dbo.ui.base.BaseActivity;
import com.smcdd.cdb.dbo.cdb_dbo.ui.utils.AnimationUtil;
import com.smcdd.cdb.dbo.cdb_dbo.ui.utils.DialogUtils;
import com.smcdd.cdb.dbo.cdb_dbo.ui.utils.ObtainUdis;
import com.smcdd.cdb.dbo.cdb_dbo.ui.widget.DrawableTextView;
import com.smcdd.cdb.dbo.cdb_dbo.ui.widget.HintDialog;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 作者：Administrator on 2017/7/5 22:30
 * 邮箱：zhanghuaiha@gmail.com
 *      统计报表
 */

public class DateInfosActivity extends BaseActivity<IDateInfos,DateInfosPresenter> implements IDateInfos{
    private TextView day_unit_set,on_line,day_single_shop;
    private TextView month_leiji,day_dabiao,reach_lay,reach_leijidb;
    private TextView mendian_history,me_history,date_detail,total_lay;
    private TextView reach_ticheng,reach_leijitc,reach_leijiticheng,date_history;
    private TextView reach_day_tc,reach_day_db,maintain_time_tv;
    private TextView sszx,sslx,pjzx,date_dbl;
    private TextView wifi_sub_count,mima_sub_count,wifi_count,mima_count;
    private TextView already_wifi_num,already_mima_num,use_wifi_num,use_mima_num;
    private TextView one,two,three,four,five,six;
    private TextView wdtc_bl1,wdtc_bl2;
    private TextView already_paper_num,use_paper_num;
    private TextView paper_sub_count,paper_count;
    private TextView pay_zong_num,pay_zong_money,pay_mima_num,pay_mima_money,pay_paper_num,pay_paper_money;
    private ImageView date_back,date_refresh,xia;
    private String udid;
    private HintDialog selfDialog;
    private RelativeLayout time;
    private LinearLayout xia_info;
    private boolean flag = false;
    private static final int TIME = 10;
    private DrawableTextView add_title;
    private Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (msg.what == TIME) {
                AnimationUtil.tranOut(DateInfosActivity.this,time);
            }
        }
    };

    @Override
    public void initView() {
        date_back = (ImageView) findViewById(R.id.date_back);
        date_refresh = (ImageView) findViewById(R.id.date_refresh);
        xia = (ImageView) findViewById(R.id.xia);
        xia_info = (LinearLayout) findViewById(R.id.xia_info);
        maintain_time_tv = (TextView) findViewById(R.id.maintain_time_tv);
        sszx = (TextView) findViewById(R.id.sszx);
        sslx = (TextView) findViewById(R.id.sslx);
        pjzx = (TextView) findViewById(R.id.pjzx);
        wdtc_bl1 = (TextView) findViewById(R.id.wdtc_bl1);
        wdtc_bl2 = (TextView) findViewById(R.id.wdtc_bl2);
        date_dbl = (TextView) findViewById(R.id.date_dbl);
        on_line = (TextView) findViewById(R.id.on_line);
        total_lay = (TextView) findViewById(R.id.total_lay);
        date_history = (TextView) findViewById(R.id.date_history);
        day_unit_set = (TextView) findViewById(R.id.day_unit_set);
        day_single_shop = (TextView) findViewById(R.id.day_single_shop);
        reach_lay = (TextView) findViewById(R.id.reach_lay);
        day_dabiao = (TextView) findViewById(R.id.day_dabiao);
        month_leiji = (TextView) findViewById(R.id.month_leiji);
        mendian_history = (TextView) findViewById(R.id.mendian_history);
        me_history = (TextView) findViewById(R.id.me_history);
        date_detail = (TextView) findViewById(R.id.date_detail);
        reach_ticheng = (TextView) findViewById(R.id.reach_ticheng);
        reach_leijitc = (TextView) findViewById(R.id.reach_leijitc);
        reach_leijidb = (TextView) findViewById(R.id.reach_leijidb);
        reach_day_tc = (TextView) findViewById(R.id.reach_day_tc);
        reach_day_db = (TextView) findViewById(R.id.reach_day_db);
        reach_leijiticheng = (TextView) findViewById(R.id.reach_leijiticheng);
        wifi_sub_count = (TextView) findViewById(R.id.wifi_sub_count);
        mima_sub_count = (TextView) findViewById(R.id.mima_sub_count);
        wifi_count = (TextView) findViewById(R.id.wifi_count);
        mima_count = (TextView) findViewById(R.id.mima_count);
        already_wifi_num = (TextView) findViewById(R.id.already_wifi_num);
        already_mima_num = (TextView) findViewById(R.id.already_mima_num);
        use_wifi_num = (TextView) findViewById(R.id.use_wifi_num);
        use_mima_num = (TextView) findViewById(R.id.use_mima_num);
        one = (TextView) findViewById(R.id.wdtc_one);
        two = (TextView) findViewById(R.id.wdtc_two);
        three = (TextView) findViewById(R.id.wdtc_three);
        five = (TextView) findViewById(R.id.wdtc_five);
        four = (TextView) findViewById(R.id.wdtc_four);
        six = (TextView) findViewById(R.id.wdtc_six);
        time = (RelativeLayout) findViewById(R.id.maintain_time);
        add_title = (DrawableTextView) findViewById(R.id.add_title);
        //我的支付
        pay_zong_num = (TextView) findViewById(R.id.pay_zong_num);
        pay_zong_money = (TextView) findViewById(R.id.pay_zong_money);
        pay_mima_num = (TextView) findViewById(R.id.pay_mima_num);
        pay_mima_money = (TextView) findViewById(R.id.pay_mima_money);
        pay_paper_num = (TextView) findViewById(R.id.pay_paper_num);
        pay_paper_money = (TextView) findViewById(R.id.pay_paper_money);
        //拥有
        already_paper_num = (TextView) findViewById(R.id.already_paper_num);
        use_paper_num = (TextView) findViewById(R.id.use_paper_num);
        //涨粉
        paper_sub_count = (TextView) findViewById(R.id.paper_sub_count);
        paper_count = (TextView) findViewById(R.id.paper_count);
    }

    @Override
    public void initData() {
        AnimationUtil.tranIn(DateInfosActivity.this, time);
        handler.sendMessageDelayed(handler.obtainMessage(TIME), 3000);
        mPresenter.loadDate();
        udid = ObtainUdis.getUDID(DateInfosActivity.class);
        mPresenter.getAll_Info(udid);
        String date = getTime(new Date(System.currentTimeMillis()));
        reach_leijitc.setText(date+"累计提成");
        reach_leijidb.setText(date+"累计达标");
    }

    private String getTime(Date date) {//可根据需要自行截取数据显示
        SimpleDateFormat format = new SimpleDateFormat("MM月");
        return format.format(date);
    }

    @Override
    public void initListener() {
        //倍率问号
        wdtc_bl1.setOnClickListener(v -> {
            DialogUtils.TSLeftDialog(DateInfosActivity.this,"涨粉提成 = 涨粉提成的百分之20\r\n 每涨一个粉提成0.3元",true);
        });
        wdtc_bl2.setOnClickListener(v -> {
            DialogUtils.TSLeftDialog(DateInfosActivity.this,"支付提成 = 支付金额的百分之20",true);
        });
        //统计问好
        add_title.setOnClickListener(v -> {
            DialogUtils.TSLeftDialog(DateInfosActivity.this,"1、凌晨5点，清除历史记录\r\n2、设备使用概念：被使用的设备台数\r\n3、单台平均：使用数 除以 涨粉数",true);
        });
        //wifi设备展开更多
        xia.setOnClickListener(v -> {
            if (xia_info.getVisibility() == View.GONE) {
                xia_info.setVisibility(View.VISIBLE);
//                Animation animation = AnimationUtils.loadAnimation(DateInfosActivity.this, R.anim.tj_cdb_in);
//                xia_info.setAnimation(animation);
                AnimationUtil.setTrans(DateInfosActivity.this,xia_info,true);
                AnimationUtil.setRotate(xia);
            }else {
                AnimationUtil.setTrans(DateInfosActivity.this,xia_info,false);

//                Animation animation = AnimationUtils.loadAnimation(DateInfosActivity.this, R.anim.tj_cdb_out);
//                xia_info.setAnimation(animation);
//                xia_info.setVisibility(View.GONE);
                AnimationUtil.setRotate2(xia);
            }
        });

        //今日提成
        reach_day_tc.setOnClickListener(v ->  {
            String hc = mPresenter.getHC();
            if (hc == null) {
                hc = "未发现该数据.";
            }
            String tc = mPresenter.getTC();
            if (tc == null) {
                tc = "未发现该数据.";
            }

            Dialog("1、今日之前已铺达标店铺的提成：" +hc+
                    "\r\n2、今日已铺店铺达标的提成："+tc);
        });
        //今日达标
        reach_day_db.setOnClickListener(v -> {
            String hn = mPresenter.getHN();
            if (hn == null) {
                hn = "未发现该数据.";
            }
            String tn = mPresenter.getTN();
            if (tn == null) {
                tn = "未发现该数据.";
            }

            Dialog("1、今日之前已铺店铺达标数：" +hn+
                    "\r\n2、今日已铺店铺达标数："+tn);
        });


        //历史明细
        date_history.setOnClickListener(v -> jumpToActivity(NewHistoryTcActivity.class));
        //本月累计达标问号
        reach_leijidb.setOnClickListener(v -> {
            Dialog("每个月底清零计算");
        });
        //本月累计提成问号
        reach_leijitc.setOnClickListener(v -> {
            Dialog("每个月底结算后清零");
        });
        date_back.setOnClickListener(v -> finish());
        //刷新
        date_refresh.setOnClickListener(v -> {
            mPresenter.getAll_Info(udid);
        });
        //查看我的历史数据
        me_history.setOnClickListener(v -> {
//            mPresenter.getMeHistory(udid);
            jumpToActivity(StatisticsTwoActivity.class);
        });
        //查看门店历史数据
        mendian_history.setOnClickListener(v -> {
            jumpToActivity(SelectShopActivity.class);
        });
        //今日明细
        date_detail.setOnClickListener(v -> {
            jumpToActivity(DetailActivity.class);
        });
        //右上角时间动画
        time.setOnClickListener(v -> {
            if (flag) {
                AnimationUtil.tranOut(DateInfosActivity.this,time);
            }else {
                AnimationUtil.tranIn(DateInfosActivity.this,time);
            }
            flag = !flag;
        });
    }

    public void Dialog(String a) {
        selfDialog = new HintDialog(this);
        selfDialog.setTitle("提示");
        selfDialog.setMessage(a);
        selfDialog.show();
    }

    @Override
    protected DateInfosPresenter createPresenter() {
        return new DateInfosPresenter(this);
    }

    @Override
    protected int provideContentViewId() {
        return R.layout.activity_date;
    }

    @Override
    public TextView getLay() {
        return total_lay;
    }

    @Override
    public TextView getLine() {
        return on_line;
    }

    @Override
    public TextView getSet() {
        return day_unit_set;
    }

    @Override
    public TextView getShop() {
        return day_single_shop;
    }

    @Override
    public TextView getReach() {
        return reach_lay;
    }

    @Override
    public TextView getDa() {
        return day_dabiao;
    }

    @Override
    public TextView getLei() {
        return month_leiji;
    }

    @Override
    public TextView getTc() {
        return reach_ticheng;
    }

    @Override
    public TextView getLjtc() {
        return reach_leijiticheng;
    }

    @Override
    public TextView getTime() {
        return maintain_time_tv;
    }

    @Override
    public TextView getsszx() {
        return sszx;
    }

    @Override
    public TextView getsslx() {
        return sslx;
    }

    @Override
    public TextView getpjzx() {
        return pjzx;
    }

    @Override
    public TextView getWifi_sub_count() {
        return wifi_sub_count;
    }

    @Override
    public TextView getMima_sub_count() {
        return mima_sub_count;
    }

    @Override
    public TextView getWifi_count() {
        return wifi_count;
    }

    @Override
    public TextView getMima_count() {
        return mima_count;
    }

    @Override
    public TextView getAlready_wifi_num() {
        return already_wifi_num;
    }

    @Override
    public TextView getAlready_mima_num() {
        return already_mima_num;
    }

    @Override
    public TextView getUse_wifi_num() {
        return use_wifi_num;
    }

    @Override
    public TextView getUse_mima_num() {
        return use_mima_num;
    }

    @Override
    public TextView getOne() {
        return one;
    }

    @Override
    public TextView getTwo() {
        return two;
    }

    @Override
    public TextView getThree() {
        return three;
    }

    @Override
    public TextView getFour() {
        return four;
    }

    @Override
    public TextView getFive() {
        return five;
    }

    @Override
    public TextView getsix() {
        return six;
    }

    @Override
    public TextView getPay_zong_num() {
        return pay_zong_num;
    }

    @Override
    public TextView getPay_zong_money() {
        return pay_zong_money   ;
    }

    @Override
    public TextView getPay_mima_num() {
        return pay_mima_num;
    }

    @Override
    public TextView getPay_mima_money() {
        return pay_mima_money;
    }

    @Override
    public TextView getPay_paper_num() {
        return pay_paper_num;
    }

    @Override
    public TextView getPay_paper_money() {
        return pay_paper_money;
    }

    @Override
    public TextView getAlready_paper_num() {
        return already_paper_num;
    }

    @Override
    public TextView getUse_paper_num() {
        return use_paper_num;
    }

    @Override
    public TextView getPaper_sub_count() {
        return paper_sub_count;
    }

    @Override
    public TextView getPaper_count() {
        return paper_count;
    }

    @Override
    public TextView getDbl() {
        return date_dbl;
    }
}
